package com.hb.trade.server.center.au.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hb.core.pojo.center.au.dto.OrgDeptDTO;
import com.hb.core.pojo.center.au.mapper.OrgDeptMapper;
import com.hb.core.pojo.center.au.entity.OrgDept;
import com.hb.core.pojo.parent.MPCommonEntity;
import com.hb.core.pojo.parent.PageResult;
import com.hb.trade.server.center.au.service.OrgDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门信息表 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2021-11-29
 */
@Service
public class OrgDeptServiceImpl extends ServiceImpl<OrgDeptMapper, OrgDept> implements OrgDeptService {
    /**
     *
     * @Description: 分页查询部门列表
     * @Author: zhongdl
     * @Date:2022/1/20 14:59
     * @param orgDept:
     * @return: {@link PageResult< OrgDeptDTO> }
     **/

    @Override
    public PageResult<OrgDeptDTO> pageOrgDept(OrgDeptDTO orgDept) {
        Page<OrgDeptDTO> pages = orgDept.pages();
        baseMapper.pageOrgDept(pages,orgDept);
        return PageResult.get(pages);
    }

    @Override
    public boolean repeatNameFlag(String deptName, Long id, Long orgId) {
        QueryWrapper<OrgDept> wrapper = OrgDept.wrapper();
        wrapper.eq("dept_name",deptName)
                .ne(id != null,"id",id)
                .eq("org_id",orgId);
        return count(wrapper) > 0;
    }

    @Override
    public List<OrgDept> listDept(QueryWrapper<OrgDept> wrapper) {
        return baseMapper.listDept(wrapper);
    }
}
